<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Admin\Setting;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Redis;

class CacheController extends Controller
{

    public function index(Request $request)
    {
        $res=['title'=>'我的'];
        //$res['user']=Auth::user();
        if($request->isMethod('post')) {
            $data['CACHE_DRIVER'] = $request->input('cache_driver');
            if(Setting::modifyEnv($data)){
                return redirect()->route('admin.cache')->with('status', 'success');
            }else{
                return back()->with('status', 'fail');
            }
        }else{
            $res['mod'] = env('CACHE_DRIVER');
            return view('admin.cache.index',['res'=>$res]);
        }
    }

    public function op(Request $request)
    {
        $res=['title'=>'我的'];
        //$res['user']=Auth::user();
//            $value =cache::remember('user', 30, function () {
//                return Auth::user()->toArray();
//            });
            //Cache::put('mykey','1234');
            //$ss = Cache::get('mykey');
            //Cache::store('redis')->put('namex', 'xxx', 600);
//            Cache::store('file')->put('name','zz1');
//            Cache::store('redis')->put('namex', 'zz2', 600);
//            Cache::add('sss', 'zzz', 600);
//            Redis::set('aa', 'xiaoming');
//            dd(Redis::get('aa'));
         return view('admin.cache.Index',['res'=>$res]);

    }


    public function flush()
    {
        Cache::flush();
        return redirect()->route('admin.cache')->with('status', 'success');
    }
}
